package com.xc.controller.backend;

import com.github.pagehelper.PageInfo;
import com.xc.common.ServerResponse;
import com.xc.service.IUserWithdrawService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author mipha
 * @version 1.0
 * @date 2019/2/28 6:01 PM
 */
@Controller
@RequestMapping("/admin/withdraw/")
@Slf4j
public class AdminWithDrawController {

    @Autowired
    IUserWithdrawService iUserWithdrawService;


    /**
     *      提现列表
     * @param agentId
     * @param userId
     * @param realName
     * @param state
     * @param beginTime
     * @param endTime
     * @param pageNum
     * @param pageSize
     * @param request
     * @return
     */
    @RequestMapping("list.do")
    @ResponseBody
    public ServerResponse<PageInfo> list(
            @RequestParam(value = "agentId",required = false) Integer agentId
            ,@RequestParam(value = "userId",required = false) Integer userId
            ,@RequestParam(value = "realName",required = false) String realName
            ,@RequestParam(value = "state",required = false) Integer state
            ,@RequestParam(value = "beginTime",required = false) String beginTime
            ,@RequestParam(value = "endTime",required = false) String endTime
            ,@RequestParam(value = "pageNum", defaultValue = "1") int pageNum
            ,@RequestParam(value = "pageSize", defaultValue = "10") int pageSize
            ,HttpServletRequest request){
        return iUserWithdrawService.listByAdmin(agentId,userId,realName
                ,state,beginTime,endTime,request,pageNum,pageSize);
    }

    /**
     *  修改提现订单状态
     * @param withId
     * @param state
     * @param authMsg
     * @return
     */
    @RequestMapping("updateState.do")
    @ResponseBody
    public ServerResponse updateState(@RequestParam(value = "withId",required = false) Integer withId
            ,@RequestParam(value = "state",required = false) Integer state
            ,@RequestParam(value = "authMsg",required = false) String authMsg){
        ServerResponse serverResponse = null;
        try {
            serverResponse = iUserWithdrawService.updateState(withId,state,authMsg);
        }catch (Exception e){
            log.error("admin修改充值订单状态出错 ，异常 = {}" , e);
        }
        return serverResponse;
    }




}
